﻿using System;

namespace WeChat.Core.Protocol
{
    /// <summary>
    /// 微信RSA版本
    /// </summary>
    public enum WXRSAVersion
    {
        /// <summary>
        /// 99版本
        /// </summary>
        [WXRSAKey("010001", "DFE56EEE6506E5F9796B4F12C3A48121B84E548E9999D834E2C037E3CD276E9C4A2B1758C582A67F6D12895CE5525DDE51D0B92D32B8BE7B2C85827729C3571DCC14B581877BC634BCC7F9DA3825C97A25B341A64295098303C4B584EC579ECCA7C8B96782F65D650039EE7A0772C195DBEFC4488BDFB0B9A58C5C058E3AB04D")]
        RSA_VER_99 = 99,
        /// <summary>
        /// 135版本
        /// </summary>
        [WXRSAKey("010001", "B5791473FDFACCE426058401B6125A3D6FEDD76C7DD1B0426A73D8A4182B29EA6D05F4F5E8D99A4D3D1C3E5CF3C8CB3CDDF935643C94D38927881B144D04F310F13307D1AE63A100A2797A714C0D1E2A5A0EF779FC3D6F7D3C3396276BF27DA6D66E2696A6557EFD4B6190C726894D35CE559E147969BAC04AFEBB0E3A235B2C795AC6A9818E14A33A4468F8FF6ABE8A54A74180042BF0FD38427F70B681B9431A099E774618D455F14D1F75121577DAE66C3853A2AA9C4F0F9C221A66F64A46D5F68B0D50F22C7E4FA0D84048B2F9179F4B86442A2720C8FE27BC68C5C6384DCC336F97914F2788B905E5FE98C5BB754488B0F6B09421BB27BFF518EF0E9299")]
        RSA_VER_135 = 135,
        /// <summary>
        /// 145版本
        /// </summary>
        [WXRSAKey("010001", "F2705A5277D50808B04C027B4503353AF7E3F36CEC05575BEA652B157D91E41BA35710E3F5F6D5675D76250A3EADB87F5B8B0AA77F8BAA86B4432878C9DE4ADA74CBD9BD69FDD711A6CE0014032BBB8B27494F1F05D22F70A1807D06C93D7A5933B5408F4BB2ECE5A04E4E0770E0D397486C14C174A511F932A0CEEA6C1B594ACDFA692F095D46C39A27C7447DE96286C0652DADA860F01F0E674D4B30A16C10005F982B1A0B3D439DD445C58A4E0AE556E999E95848C13E9837B1C10996AAA9F02D8B99D2D561CF97D171E87CC77656CAC5345888936018CBBEA325FF50FE52B86827A712B5CC9FD44121EE8BD6D0EFF20B75BB57E2AE698C1BB3C6769BAF53", Description = "Mac-2.3.29-AuthCert")]
        RSA_VER_145 = 145,
        /// <summary>
        /// 156版本
        /// </summary>
        [WXRSAKey("010001", "BFEDFFB5EA28509F9C89ED83FA7FDDA8881435D444E984D53A98AD8E9410F1145EDD537890E10456190B22E6E5006455EFC6C12E41FDA985F38FBBC7213ECB810E3053D4B8D74FFBC70B4600ABD728202322AFCE1406046631261BD5EE3D44721082FEAB74340D73645DC0D02A293B962B9D47E4A64100BD7524DE00D9D3B5C1")]
        RSA_VER_156 = 156,
        /// <summary>
        /// 158版本
        /// </summary>
        [WXRSAKey("010001", "E161DA03D0B6AAD21F9A4FB27C32A3208AF25A707BB0E8ECE79506FBBAF97519D9794B7E1B44D2C6F2588495C4E040303B4C915F172DD558A49552762CB28AB309C08152A8C55A4DFC6EA80D1F4D860190A8EE251DF8DECB9B083674D56CD956FF652C3C724B9F02BE5C7CBC63FC0124AA260D889A73E91292B6A02121D25AAA7C1A87752575C181FFB25A6282725B0C38A2AD57676E0884FE20CF56256E14529BC7E82CD1F4A1155984512BD273D68F769AF46E1B0E3053816D39EB1F0588384F2F4B286E5CFAFB4D0435BDF7D3AA8D3E0C45716EAD190FDC66884B275BA08D8ED94B1F84E7729C25BD014E7FA3A23123E10D3A93B4154452DDB9EE5F8DAB67")]
        RSA_VER_158 = 158,
        /// <summary>
        /// 172版本
        /// </summary>
        [WXRSAKey("010001", "A69E974E15B895D5530CFF97EAD82B12D4B86D7926D7EB3D17357037BFFD0DBAA1CE100DBE462A1F68D2A12C967C14F5224C32B06E67A34DDD9C20F9A2306D0AE4768A2F24D4E2553AA05B67B9327737B4163C9F4B4AB02D840401AEB93EB617EBC8CA549628A9CC82ED5E0C78267170D18B254214B477280C52F72D1F2710170014F7FFE6C104CF2A540C7331855F6A1ACD5F50661BEC228D107532FF8AB7CEB9C15AD7EDB84D88097C92C71FCF043513DCC1C64AA004B8EBFD6CE139E0F55601C715366CFB8045EA7C9831E1AA9E5B125D41C138BF809841E703836FA9D227D0C5C4F88C4B7387B00BBFD4B90C12F793CA750EA5ED32ABBED70B82A890F7C7")]
        RSA_VER_172 = 172,
        /// <summary>
        /// 174版本
        /// </summary>
        [WXRSAKey("010001", "D153E8A2B314D2110250A0A550DDACDCD77F5801F3D1CC21CB1B477E4F2DE8697D40F10265D066BE8200876BB7135EDC74CDBC7C4428064E0CDCBE1B6B92D93CEAD69EC27126DEBDE564AAE1519ACA836AA70487346C85931273E3AA9D24A721D0B854A7FCB9DED49EE03A44C189124FBEB8B17BB1DBE47A534637777D33EEC88802CD56D0C7683A796027474FEBF237FA5BF85C044ADC63885A70388CD3696D1F2E466EB6666EC8EFE1F91BC9353F8F0EAC67CC7B3281F819A17501E15D03291A2A189F6A35592130DE2FE5ED8E3ED59F65C488391E2D9557748D4065D00CBEA74EB8CA19867C65B3E57237BAA8BF0C0F79EBFC72E78AC29621C8AD61A2B79B", Description = "iPad-7.0.8-AuthCert")]
        RSA_VER_174 = 174,
        /// <summary>
        /// 178版本
        /// </summary>
        [WXRSAKey("010001", "30820122300D06092A864886F70D01010105000382010F003082010A0282010100B2EA42C45BABB1BF2DBE3D565963420B70BA7F82B375D9208549721CF179E59927815BC414AA66C0771F382F74D8385821FA39591E28996735BC1EE1190B225C4BFFE5BDA7D035057C2593061887A1DD58378B28F217C4181BE737804BED14046CA8D0FDED39C91BFE17DEE864CEF3901DAA15F4BD9E8A82294C023A0CA2E1FE5F26A11BCC35244DFFAB72025A7F002FB7887634E9F8D725A0679295D3EFA166EDEA063D635C3A3DDBAA25824D4FDF8B8B5035768B202A91538D34A0B867E3E730F721DF4A81C6963852AF28A47FAEEF4D90C84580F5D2BC41B74255343A3B18F74BC5635CDF9D485EC71DE109F7629C969D026E621193032C87AB76AF54D2210203010001")]
        RSA_VER_178 = 178,
        /// <summary>
        /// 180版本
        /// </summary>
        [WXRSAKey("010001", "A770028BA38DDB08252B6C41C201838553E75552DE0B8EC10DF3E2B6F641026644178D7C362912C51B8CE18682C8502C18B1ACB05A45C725E4EE4F4C8C4FE08D5C8D75FA305175D2595DF5632413E897AE5366ED1A63146B8B0AEE9D955999331B23988F7564FCA291E01E36CA3AE78116FCFDB7AB8A881B33DF687C59E3918A51F5D37C5C20401EE3CFDA007094C904ED4CCE96981548D04EDAD3EAD0071DD75C2C2AA07E5686781BD3723A1305FFB5EBA785B0A50B39EA5003599591ADDAF75B20B8E5048A0B1116CD8A368D54352E73E2FC884F4DE7FE451DE05CBA147BFBDC7A82D3A24C6F5D3F0698B57522E8B4075735A1D1E6D9F531B8C977B8E0619B")]
        RSA_VER_180 = 180,
        /// <summary>
        /// 182版本
        /// </summary>
        [WXRSAKey("010001", "C8930AB6E688F68513682FA555E1A3C175867CDC4AAE1D054F75134D1553D9E4A1BBC846FBAEE947E1515363365185AEB39C9DD5B76BF8ADE21233E27728BC0ED8C465CCC7DBABC7EBE08B1FA23A89098D7730C31FBE375745A9AA717D7F3DE5FB8126B6D6B2B9EB1643346F00EBE3A2AA915A417B263E4026FEF4BFA91B81B035DE224857E87FB292FB9AFBAC45725D968068385963E3CDB0162C901D0921030515D1CA1E079129DD585969EF6CBABBE72E287D9A9F757FAE91543F5AADD96777BE49D1CEF58669250DB4B992C01AFE22AF5DDDB0147BD5C8B373F39381A1E914078050239D490B6FC02E68B61A81BCE0ED9710BC84481273E32ED89ACD5211", Description = "iPad-7.0.5-AuthCert")]
        RSA_VER_182 = 182
    }
    /// <summary>
    /// 微信RSA密钥特性标记
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public sealed partial class WXRSAKeyAttribute : Attribute
    {
        /// <summary>
        /// 指数
        /// </summary>
        public string Exponent { get; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string Key { get; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exponent"></param>
        /// <param name="key"></param>
        public WXRSAKeyAttribute(string exponent, string key)
        {
            Exponent = exponent;
            Key = key;
        }
    }
    /// <summary>
    /// 微信RSA密钥扩展
    /// </summary>
    public static partial class WXRSAKeyExtensions
    {
        /// <summary>
        /// 获取Key
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static string GetKey(this WXRSAVersion target)
        {
            var result = default(string);
            var attris = target.GetType().GetField(target.ToString()).GetCustomAttributes(typeof(WXRSAKeyAttribute), true);
            if (attris != null && attris.Length > 0)
            {
                WXRSAKeyAttribute coAttrs = attris[0] as WXRSAKeyAttribute;
                result = coAttrs.Key;
            }
            return result;
        }
        /// <summary>
        /// 获取Exponent
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static string GetExponent(this WXRSAVersion target)
        {
            var result = default(string);
            var attris = target.GetType().GetField(target.ToString()).GetCustomAttributes(typeof(WXRSAKeyAttribute), true);
            if (attris != null && attris.Length > 0)
            {
                WXRSAKeyAttribute coAttrs = attris[0] as WXRSAKeyAttribute;
                result = coAttrs.Exponent;
            }
            return result;
        }
    }
}